package com.dmbjz.openApi.config;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OpenApiConfig {

    //根据请求路径对API进行分组
    @Bean
    public GroupedOpenApi personApi() {
        return GroupedOpenApi.builder()
                .group("人员管理")
                .pathsToMatch("/person/**")
                .build();
    }

    //根据请求路径对API进行分组
    @Bean
    public GroupedOpenApi addressApi() {
        return GroupedOpenApi.builder()
                .group("地址管理")
                .pathsToMatch("/address/**")
                //指定需要有对应注解，才会生成文档
                .addOpenApiMethodFilter(method -> method.isAnnotationPresent(Operation.class))
                .build();
    }


    /**
     * 配置 OpenAPI 界面说明
     */
    @Bean
    public OpenAPI springShopOpenAPI() {
        return new OpenAPI()
                .info(new Info().title("OpenAPI 模块 API")
                        .description("基于 SpirngBoot 3.1.11 ")
                        .version("v1.0.0")
                        .license(new License().name("Apache 2.0").url("http://springdoc.org")))
                .externalDocs(new ExternalDocumentation()
                        .description("友情链接")
                        .url("https://www.baidu.com"));
    }

}
